﻿using UnityEditor;
using UnityEngine;

namespace CWM.Skinn
{
    public static partial class SkinnContextCommands
    {
        [CtxMenuItem("SkinnedMeshRenderer/Skin/Bind-pose",
            "The bind-pose is the rest pose of the skinning. " +
            "Creates a bind-pose that matches the current bone positions.", 0)]
        public static void SkinnedMeshBindposeLocal()
        {
            foreach (var item in SkinnContext.GetContextItems())
            {
                var context = item.GetComponent<SkinnedMeshRenderer>();
                if (SkinnEx.IsNullOrNotInAScene(context)) continue;
                SkinnContext.UndoRecord(context, "Bind-pose");
                context.BakeAndBindpose(false);
            }

            SkinnContext.Finished();
        }
    }
}